package br.com.translog.gui.cliente;

import br.com.translog.fachada.FachadaTranslog;
import br.com.translog.gui.outro.FrmMenuPrincipal;
import br.com.translog.modelo.Cliente;
import br.com.translog.modelo.Logradouro;
import br.com.translog.modelo.PessoaJuridica;
import javax.swing.JOptionPane;

public class FrmClienteAlterar extends javax.swing.JFrame {

    /**
     * Creates new form FrmClienteAlterar
     */
    public FrmClienteAlterar() {
        initComponents();
        setLocationRelativeTo(null);
    }
    
    //Instanciando os objetos que serao utilizados...
    int codigoLogradouro = 0;
    int codigoPessoaJuridica = 0;

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT
     * modify this code. The content of this method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlClienteAlterar = new javax.swing.JPanel();
        lblAlteraCliente = new javax.swing.JLabel();
        lblCNPJ = new javax.swing.JLabel();
        lblCodigoCliente = new javax.swing.JLabel();
        lblRazaoSocial = new javax.swing.JLabel();
        lblNomeFantasia = new javax.swing.JLabel();
        lblEndereco = new javax.swing.JLabel();
        lblNumero = new javax.swing.JLabel();
        lblCEP = new javax.swing.JLabel();
        lblComplemento = new javax.swing.JLabel();
        lblBairro = new javax.swing.JLabel();
        lblCidade = new javax.swing.JLabel();
        lblEstado = new javax.swing.JLabel();
        lblEmail = new javax.swing.JLabel();
        lblTelefoneComercial = new javax.swing.JLabel();
        lblSite = new javax.swing.JLabel();
        txtCNPJ = new javax.swing.JTextField();
        txtCodigoCliente = new javax.swing.JTextField();
        txtRazaoSocial = new javax.swing.JTextField();
        txtNomeFantasia = new javax.swing.JTextField();
        txtEndereco = new javax.swing.JTextField();
        txtNumero = new javax.swing.JTextField();
        txtCEP = new javax.swing.JTextField();
        txtComplemento = new javax.swing.JTextField();
        txtEmail = new javax.swing.JTextField();
        txtTelefoneComercial = new javax.swing.JTextField();
        txtSite = new javax.swing.JTextField();
        cmbBairro = new javax.swing.JComboBox();
        cmbCidade = new javax.swing.JComboBox();
        cmbEstado = new javax.swing.JComboBox();
        btnPesquisar = new javax.swing.JButton();
        btnAtualizar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        pnlClienteAlterar.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        pnlClienteAlterar.setMaximumSize(new java.awt.Dimension(946, 278));
        pnlClienteAlterar.setMinimumSize(new java.awt.Dimension(946, 278));

        lblAlteraCliente.setFont(new java.awt.Font("Tahoma", 1, 15)); // NOI18N
        lblAlteraCliente.setText("ALTERAR CLIENTE");
        lblAlteraCliente.setName(""); // NOI18N

        lblCNPJ.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblCNPJ.setText("CNPJ");

        lblCodigoCliente.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblCodigoCliente.setText("Código Cliente");

        lblRazaoSocial.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblRazaoSocial.setText("Razão social");

        lblNomeFantasia.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblNomeFantasia.setText("Nome Fantasia");

        lblEndereco.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblEndereco.setText("Endereço");

        lblNumero.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblNumero.setText("Número");

        lblCEP.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblCEP.setText("CEP");

        lblComplemento.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblComplemento.setText("Complemento");

        lblBairro.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblBairro.setText("Bairro");

        lblCidade.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblCidade.setText("Cidade");

        lblEstado.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblEstado.setText("Estado");

        lblEmail.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblEmail.setText("Email");

        lblTelefoneComercial.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblTelefoneComercial.setText("Telefone Comercial");

        lblSite.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblSite.setText("Site");

        txtCodigoCliente.setEditable(false);

        cmbBairro.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "SELECIONE A OPCAO", "AFLITOS", "AFOGADOS", "AGUA FRIA", "AGUAS COMPRIDAS", "AGUAZINHA", "ALTO 13 DE FEVEREIRO", "ALTO DA BONDADE", "ALTO DA BRASILEIRA", "ALTO DA CONQUISTA", "ALTO DA FOICE", "ALTO DA SAUDADE", "ALTO DA TELHA", "ALTO DO BRASIL", "ALTO DO BURITY", "ALTO DO CAPITAO", "ALTO DO CARROCEIRO", "ALTO DO CEU", "ALTO DO DEODATO", "ALTO DO EUCALIPTO", "ALTO DO FORMOSO", "ALTO DO MANDU", "ALTO DO PASCOAL", "ALTO DO PROGRESSO", "ALTO DO RESERVATORIO", "ALTO DO SOL NASCENTE", "ALTO DOS COQUEIROS", "ALTO JOSE BONIFACIO", "ALTO JOSE DO PINHO", "ALTO SANTA ISABEL", "ALTO SANTA TERESINHA", "ALTO VISCONDE GARRET", "AMARO BRANCO", "AMPARO", "APIPUCOS", "AREIAS", "ARRUDA", "ARTHUR LUNDGREN I", "ARTHUR LUNDGREN II", "BAIRRO NOVO", "BARRA DE JANGADA", "BARREIRA DO ROSARINHO", "BARRO", "BEBERIBE", "BEIRA RIO", "BENFICA", "BOA VIAGEM", "BOA VISTA", "BOMBA DO HEMETERIO", "BOMBA GRANDE", "BONGI", "BONSUCESSO", "BRASILIA TEIMOSA", "BREJO DA GUABIRABA", "BREJO DE BEBERIBE", "BULHOES", "BULTRINS", "BURITI", "CABANGA", "CACOTE", "CAIXA D AGUA", "CAJUEIRO SECO", "CAJUEIRO", "CAMPINA DO BARRETO", "CAMPO GRANDE", "CANDEIAS", "CAPUNGA", "CARMO", "CASA AMARELA", "CASA CAIADA", "CASA FORTE", "CAVALEIRO", "CAXANGA", "CENTRO", "CIDADE UNIVERSITARIA", "COELHOS", "COHAB", "CONJUNTO MARCOS FREIRE", "CONJUNTO MURIBECA", "COQUE", "COQUEIRAL", "CORDEIRO", "CORREGO DA AREIA", "CORREGO DA BICA", "CORREGO DO BARTOLEMEU", "CORREGO DO CARUA", "CORREGO DO EUCLIDES", "CORREGO DO JENIPAPO", "CORREGO DO JOAQUIM", "CURADO", "DERBY", "DOIS IRMAOS", "DOIS UNIDOS", "ENCRUZILHADA", "ENGENHO DO MEIO", "ENGENHO MARANGUAPE", "ENGENHO VELHO", "ESPINHEIRO", "ESTANCIA", "FLORIANO", "FRAGOSO", "FUNDAO", "GRACAS", "GUABIRABA", "GUADALUPE", "HIPODROMO", "IBURA", "ILHA DE DEUS", "ILHA DO LEITE", "ILHA DO RETIRO", "ILHA JOANA BEZERRA", "IMBIRIBEIRA", "INOCOOP", "IPIRANGA", "IPSEP", "IPUTINGA", "JABOATAO", "JAGUARANA", "JAGUARIBE", "JANGA", "JAQUEIRA", "JARDIM ATLANTICO", "JARDIM BEIRA RIO", "JARDIM BOA VIAGEM", "JARDIM BOTANICO", "JARDIM BRASIL", "JARDIM DOM BOSCO", "JARDIM EUROPA", "JARDIM IMBIRIBEIRA", "JARDIM JUCARA", "JARDIM MARANGUAPE", "JARDIM SANTO ANTONIO", "JARDIM SAO PAULO", "JARDIM SAO SEBASTIAO", "JARDIM VELHO", "JIQUIA", "JOANA BEZERRA", "JORDAO", "LINHA DO TIRO", "MACAXEIRA", "MADALENA", "MANASSU", "MANGABEIRA", "MANGUEIRA", "MARANGUAPE I", "MARANGUAPE II", "MILAGRES", "MIRUEIRA", "MONTE", "MONTEIRO", "MORRO DA CONCEICAO", "MURIBECA DOS GUARARAPES", "MURIBEQUINHA", "MUSTARDINHA", "NOBRE", "NOSSA SENHORA DA CONCEICAO", "NOSSA SENHORA DO O", "NOVA DESCOBERTA", "OURO PRETO", "PAISSANDU", "PARNAMIRIM", "PARQUE DO JANGA", "PASSARINHO", "PAU AMARELO", "PAU FERRO", "PEIXINHOS", "PIEDADE", "PINA", "PINHEIRO", "POCO DA PANELA", "PONTE D UCHOA", "PONTO DE PARADA", "PORTO DA MADEIRA", "POTY", "PRADO", "PRAZERES", "RECIFE", "RIO DOCE", "ROSARINHO", "SALGADINHO", "SAN MARTIN", "SANCHO", "SANTA TEREZA", "SANTANA", "SANTO ALEIXO", "SANTO AMARO", "SANTO ANTONIO", "SAO BENEDITO", "SAO JOSE", "SAPUCAIA", "SETUBAL", "SITIO DOS PINTOS", "SITIO NOVO", "SOCORRO", "SOLEDADE", "TABAJAR", "TABAJARA", "TAMARINEIRA", "TEJIPIO", "TORRE", "TORREAO", "TORRES GALVAO", "TORROES", "TOTO", "VARADOURO", "VARGEM FRIA", "VARZEA", "VASCO DA GAMA", "VILA CARDEAL E SILVA", "VILA DO SESI", "VILA POPULAR", "VILA RICA", "VILA TAMANDARE", "VISTA ALEGRE", "ZUMBI" }));

        cmbCidade.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "SELECIONE A OPCAO", "ABREU E LIMA", "AFOGADOS DA INGAZEIRA", "AFRANIO", "AGRESTINA", "AGUA PRETA", "AGUAS BELAS", "ALAGOINHA", "ALIANCA", "ALTINHO", "AMARAJI", "ANGELIM", "ARACOIABA", "ARARIPINA", "ARCOVERDE", "BARRA DE GUABIRABA", "BARREIROS", "BELEM DE MARIA", "BELEM DE SAO FRANCISCO", "BELO JARDIM", "BETANIA", "BEZERROS", "BODOCO", "BOM CONSELHO", "BOM JARDIM", "BONITO", "BREJAO", "BREJINHO", "BREJO DA MADRE DE DEUS", "BUENOS AIRES", "BUIQUE", "CABO DE SANTO AGOSTINHO", "CABROBO", "CACHOEIRINHA", "CAETES", "CALCADO", "CALUMBI", "CAMARAGIBE", "CAMOCIM DE SAO FELIX", "CAMUTANGA", "CANHOTINHO", "CAPOEIRAS", "CARNAIBA", "CARNAUBEIRA DA PENHA", "CARPINA", "CARUARU", "CASINHAS", "CATENDE", "CEDRO", "CHA DE ALEGRIA", "CHA GRANDE", "CONDADO", "CORRENTES", "CORTES", "CUMARU", "CUPIRA", "CUSTODIA", "DORMENTES", "ESCADA", "EXU", "FEIRA NOVA", "FERNANDO DE NORONHA", "FERREIROS", "FLORES", "FLORESTA", "FREI MIGUELINHO", "GAMELEIRA", "GARANHUNS", "GLORIA DO GOITA", "GOIANA", "GRANITO", "GRAVATA", "IATI", "IBIMIRIM", "IBIRAJUBA", "IGARASSU", "IGUARACI", "INAJA", "INGAZEIRA", "IPOJUCA", "IPUBI", "ITACURUBA", "ITAIBA", "ITAMARACA", "ITAMBE", "ITAPETIM", "ITAPISSUMA", "ITAQUITINGA", "JABOATAO DOS GUARARAPES", "JAQUEIRA", "JATAUBA", "JATOBA", "JOAO ALFREDO", "JOAQUIM NABUCO", "JUCATI", "JUPI", "JUREMA", "LAGOA DO CARRO", "LAGOA DO ITAENGA", "LAGOA DO OURO", "LAGOA DOS GATOS", "LAGOA GRANDE", "LAJEDO", "LIMOEIRO", "MACAPARANA", "MACHADOS", "MANARI", "MARAIAL", "MIRANDIBA", "MOREILANDIA", "MORENO", "NAZARE DA MATA", "OLINDA", "OROBO", "OROCO", "OURICURI", "PALMARES", "PALMEIRINA", "PANELAS", "PARANATAMA", "PARNAMIRIM", "PASSIRA", "PAUDALHO", "PAULISTA", "PEDRA", "PESQUEIRA", "PETROLANDIA", "PETROLINA", "POCAO", "POMBOS", "PRIMAVERA", "QUIPAPA", "QUIXABA", "RECIFE", "RIACHO DAS ALMAS", "RIBEIRAO", "RIO FORMOSO", "SAIRE", "SALGADINHO", "SALGUEIRO", "SALOA", "SANHARO", "SANTA CRUZ", "SANTA CRUZ DA BAIXA VERDE", "SANTA CRUZ DO CAPIBARIBE", "SANTA FILOMENA", "SANTA MARIA DA BOA VISTA", "SANTA MARIA DO CAMBUCA", "SANTA TEREZINHA", "SAO BENEDITO DO SUL", "SAO BENTO DO UNA", "SAO CAITANO", "SAO JOAO", "SAO JOAQUIM DO MONTE", "SAO JOSE DA COROA GRANDE", "SAO JOSE DO BELMONTE", "SAO JOSE DO EGITO", "SAO LOURENCO DA MATA", "SAO VICENTE FERRER", "SERRA TALHADA", "SERRITA", "SERTANIA", "SIRINHAEM", "SOLIDAO", "SURUBIM", "TABIRA", "TACAIMBO", "TACARATU", "TAMANDARE", "TAQUARITINGA DO NORTE", "TEREZINHA", "TERRA NOVA", "TIMBAUBA", "TORITAMA", "TRACUNHAEM", "TRINDADE", "TRIUNFO", "TUPANATINGA", "TUPARETAMA", "VENTUROSA", "VERDEJANTE", "VERTENTE DO LERIO", "VERTENTES", "VICENCIA", "VITORIA DE SANTO ANTAO", "XEXEU" }));

        cmbEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "SELECIONE A OPCAO", "ACRE", "ALAGOAS", "AMAPA", "AMAZONAS", "BAHIA", "CEARA", "DISTRITO FEDERAL", "ESPIRITO SANTO", "GOIAS", "MARANHAO", "MATO GROSSO", "MATO GROSSO DO SUL", "MINAS GERAIS", "PARA", "PARAIBA", "PARANA", "PERNAMBUCO", "PIAUI", "RIO DE JANEIRO", "RIO GRANDE DO NORTE", "RIO GRANDE DO SUL", "RONDONIA", "RORAIMA", "SANTA CATARINA", "SAO PAULO", "SERGIPE", "TOCANTINS" }));

        btnPesquisar.setText("Pesquisar");
        btnPesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesquisarActionPerformed(evt);
            }
        });

        btnAtualizar.setText("Atualizar");
        btnAtualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAtualizarActionPerformed(evt);
            }
        });

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlClienteAlterarLayout = new javax.swing.GroupLayout(pnlClienteAlterar);
        pnlClienteAlterar.setLayout(pnlClienteAlterarLayout);
        pnlClienteAlterarLayout.setHorizontalGroup(
            pnlClienteAlterarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlClienteAlterarLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlClienteAlterarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlClienteAlterarLayout.createSequentialGroup()
                        .addComponent(lblRazaoSocial)
                        .addGap(18, 18, 18)
                        .addGroup(pnlClienteAlterarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlClienteAlterarLayout.createSequentialGroup()
                                .addComponent(txtEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(lblNumero)
                                .addGap(18, 18, 18)
                                .addComponent(txtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(lblCEP)
                                .addGap(18, 18, 18)
                                .addComponent(txtCEP))
                            .addGroup(pnlClienteAlterarLayout.createSequentialGroup()
                                .addGroup(pnlClienteAlterarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(lblAlteraCliente)
                                    .addGroup(pnlClienteAlterarLayout.createSequentialGroup()
                                        .addComponent(txtRazaoSocial, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addGroup(pnlClienteAlterarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(lblCodigoCliente)
                                            .addComponent(lblNomeFantasia))))
                                .addGap(18, 18, 18)
                                .addGroup(pnlClienteAlterarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtNomeFantasia)
                                    .addGroup(pnlClienteAlterarLayout.createSequentialGroup()
                                        .addComponent(txtCodigoCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(0, 0, Short.MAX_VALUE))))))
                    .addGroup(pnlClienteAlterarLayout.createSequentialGroup()
                        .addComponent(lblEmail)
                        .addGap(53, 53, 53)
                        .addGroup(pnlClienteAlterarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtSite, javax.swing.GroupLayout.PREFERRED_SIZE, 351, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(pnlClienteAlterarLayout.createSequentialGroup()
                                .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 351, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(lblTelefoneComercial)
                                .addGap(18, 18, 18)
                                .addComponent(txtTelefoneComercial, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(lblSite)
                    .addGroup(pnlClienteAlterarLayout.createSequentialGroup()
                        .addGroup(pnlClienteAlterarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblComplemento)
                            .addComponent(lblCNPJ)
                            .addComponent(lblEndereco))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlClienteAlterarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlClienteAlterarLayout.createSequentialGroup()
                                .addComponent(txtCNPJ, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(btnPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(pnlClienteAlterarLayout.createSequentialGroup()
                                .addComponent(txtComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(lblBairro)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cmbBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(20, 20, 20)
                                .addComponent(lblCidade)
                                .addGap(27, 27, 27)
                                .addComponent(cmbCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(lblEstado)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
                                .addComponent(cmbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlClienteAlterarLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(btnAtualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(46, 46, 46)
                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(329, 329, 329))
        );
        pnlClienteAlterarLayout.setVerticalGroup(
            pnlClienteAlterarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlClienteAlterarLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblAlteraCliente)
                .addGap(18, 18, 18)
                .addGroup(pnlClienteAlterarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlClienteAlterarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblCNPJ)
                        .addComponent(txtCNPJ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnPesquisar))
                    .addGroup(pnlClienteAlterarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblCodigoCliente)
                        .addComponent(txtCodigoCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(pnlClienteAlterarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtRazaoSocial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblNomeFantasia)
                    .addComponent(txtNomeFantasia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblRazaoSocial))
                .addGap(18, 18, 18)
                .addGroup(pnlClienteAlterarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEndereco)
                    .addComponent(txtEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblNumero)
                    .addComponent(txtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblCEP)
                    .addComponent(txtCEP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlClienteAlterarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblComplemento)
                    .addComponent(txtComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblBairro)
                    .addComponent(lblCidade)
                    .addComponent(lblEstado)
                    .addComponent(cmbBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmbCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlClienteAlterarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEmail)
                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblTelefoneComercial)
                    .addComponent(txtTelefoneComercial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlClienteAlterarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblSite)
                    .addComponent(txtSite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlClienteAlterarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAtualizar)
                    .addComponent(btnCancelar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlClienteAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlClienteAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnPesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesquisarActionPerformed

        //Instanciando os objetos que serao utilizados...
        PessoaJuridica pj;
        
        try {
            //Verifica se o campo de pesquisa nao esta em "branco"...
            if (!txtCNPJ.getText().equals("")) {
                pj = FachadaTranslog.getInstFachadaTranslog().consultaCliente(Integer.parseInt(txtCNPJ.getText()));
                if (pj == null) {
                    JOptionPane.showMessageDialog(null, "Cliente não Encontrado!");
                } else {
                    //Setando os valores do objeto cliente nos JTextFields...
                    codigoPessoaJuridica = pj.getCodigo();
                    codigoLogradouro = pj.getCliente().getCodigoLogradouro().getCodigo();
                    txtCEP.setText(String.valueOf(pj.getCliente().getCodigoLogradouro().getCep()));
                    txtCNPJ.setText(String.valueOf(pj.getCnpj()));
                    txtCodigoCliente.setText(String.valueOf(pj.getCliente().getCodigo()));
                    txtComplemento.setText(pj.getCliente().getCodigoLogradouro().getComplemento());
                    txtEmail.setText(pj.getEmail());
                    txtEndereco.setText(pj.getCliente().getCodigoLogradouro().getEndereco());
                    txtNomeFantasia.setText(pj.getNomeFantasia());
                    txtNumero.setText(pj.getCliente().getCodigoLogradouro().getNumero());
                    txtRazaoSocial.setText(pj.getRazaoSocial());
                    txtSite.setText(pj.getSite());
                    txtTelefoneComercial.setText(String.valueOf(pj.getTelefoneComercial()));
                    cmbBairro.setSelectedItem(pj.getCliente().getCodigoLogradouro().getCodigoBairro().getNome());
                    cmbCidade.setSelectedItem(pj.getCliente().getCodigoLogradouro().getCodigoCidade().getNome());
                    cmbEstado.setSelectedItem(pj.getCliente().getCodigoLogradouro().getCodigoEstado().getNome());
                    
                }
                
            } else {
                JOptionPane.showMessageDialog(null, "Dados Obrigatórios não Informados!");
            }
            
        } catch (Exception e) {
        }
    }//GEN-LAST:event_btnPesquisarActionPerformed

    private void btnAtualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAtualizarActionPerformed

        //Instanciando os objetos que serao utilizados...
        Cliente c = new Cliente();
        PessoaJuridica pj = new PessoaJuridica();
        Logradouro l = new Logradouro();

        try {
            //Preenchendo o objeto PessoaJuridica...
            pj.setCnpj(Long.parseLong(txtCNPJ.getText()));
            pj.setEmail(txtEmail.getText());
            pj.setNomeFantasia(txtNomeFantasia.getText());
            pj.setRazaoSocial(txtRazaoSocial.getText());
            pj.setSite(txtSite.getText());
            pj.setTelefoneComercial(Long.parseLong(txtTelefoneComercial.getText()));

            //Preenchendo o objeto Logradouro...
            l.setCep(Long.parseLong(txtCEP.getText()));
            l.setCodigoBairro(FachadaTranslog.getInstFachadaTranslog().validaBairro((String) cmbBairro.getSelectedItem().toString()));
            l.setCodigoCidade(FachadaTranslog.getInstFachadaTranslog().validaCidade((String) cmbCidade.getSelectedItem().toString()));
            l.setCodigoEstado(FachadaTranslog.getInstFachadaTranslog().validaEstado((String) cmbEstado.getSelectedItem().toString()));
            l.setComplemento(txtComplemento.getText());
            l.setEndereco(txtEndereco.getText());
            l.setNumero(txtNumero.getText());

            //Preenchendo o objeto Cliente...
            /*c.setCodigoPessoaJuridica(pj.getCliente().getCodigoPessoaJuridica());
            c.setCodigoLogradouro(l.getCliente().getCodigoLogradouro());
            c.setMatriculaFuncionario(FachadaTranslog.getInstFachadaTranslog().getFuncionario());
            */
            
            c.setCodigoPessoaJuridica(pj);
            c.setCodigoLogradouro(l);
            c.setMatriculaFuncionario(FachadaTranslog.getInstFachadaTranslog().getFuncionario());

            //Passando os objetos para serem persistidos...
            FachadaTranslog.getInstFachadaTranslog().alteraCliente(c, pj, l);
            
            JOptionPane.showMessageDialog(null, "Dados Atualizados");
            
            //Limpando o formulario para uma nova ação...
           txtCNPJ.setText(null);
           txtEmail.setText(null);
           txtNomeFantasia.setText(null);
           txtRazaoSocial.setText(null);
           txtSite.setText(null);
           txtTelefoneComercial.setText(null);
           txtCEP.setText(null);
           cmbBairro.setSelectedItem("SELECIONE A OPCAO");
           cmbCidade.setSelectedItem("SELECIONE A OPCAO");
           cmbEstado.setSelectedItem("SELECIONE A OPCAO");
           txtComplemento.setText(null);
           txtEndereco.setText(null);
           txtNumero.setText(null);

            
           
            
            
            
            
            
            
        } catch (Exception e) {
        }
    }//GEN-LAST:event_btnAtualizarActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        
        new FrmMenuPrincipal().setVisible(true);
        this.dispose();
        
    }//GEN-LAST:event_btnCancelarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmClienteAlterar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmClienteAlterar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmClienteAlterar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmClienteAlterar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new FrmClienteAlterar().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAtualizar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnPesquisar;
    private javax.swing.JComboBox cmbBairro;
    private javax.swing.JComboBox cmbCidade;
    private javax.swing.JComboBox cmbEstado;
    private javax.swing.JLabel lblAlteraCliente;
    private javax.swing.JLabel lblBairro;
    private javax.swing.JLabel lblCEP;
    private javax.swing.JLabel lblCNPJ;
    private javax.swing.JLabel lblCidade;
    private javax.swing.JLabel lblCodigoCliente;
    private javax.swing.JLabel lblComplemento;
    private javax.swing.JLabel lblEmail;
    private javax.swing.JLabel lblEndereco;
    private javax.swing.JLabel lblEstado;
    private javax.swing.JLabel lblNomeFantasia;
    private javax.swing.JLabel lblNumero;
    private javax.swing.JLabel lblRazaoSocial;
    private javax.swing.JLabel lblSite;
    private javax.swing.JLabel lblTelefoneComercial;
    private javax.swing.JPanel pnlClienteAlterar;
    private javax.swing.JTextField txtCEP;
    private javax.swing.JTextField txtCNPJ;
    private javax.swing.JTextField txtCodigoCliente;
    private javax.swing.JTextField txtComplemento;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtEndereco;
    private javax.swing.JTextField txtNomeFantasia;
    private javax.swing.JTextField txtNumero;
    private javax.swing.JTextField txtRazaoSocial;
    private javax.swing.JTextField txtSite;
    private javax.swing.JTextField txtTelefoneComercial;
    // End of variables declaration//GEN-END:variables
}
